package com.lbb.simple.demo.utils

import com.lbb.http.GsonUtil
import com.lbb.simple.demo.bean.User
import com.lbb.utils.SpUtil

object UserUtil {
    private const val USER = "USER_INFO"
    private const val TOKEN = "USER_TOKEN"
    fun setUser(user: String) {
        SpUtil.setValue(USER, user)
        val userBean = GsonUtil.toBean(user, User::class.java)
        userBean?.let {
            SpUtil.setValue(TOKEN, it.token)
        }
    }

    fun getUser(): User? {
        if (SpUtil.getStringValue(USER).isNullOrEmpty()) {
            return null
        }
        return GsonUtil.toBean(SpUtil.getStringValue(USER), User::class.java)
    }
}